<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        div {
            /* demo说明文字 */
            color: #333;
            font-size: 16px;
            width: 700px;
            margin: 80px auto;
        }
        
        a {
            text-decoration: none;
            font-size: 14px;
        }
        
        li {
            list-style-type: none;
        }
        
        .nav {
            margin: 100px;
        }
        
        .nav>li {
            position: relative;
            float: left;
            width: 80px;
            height: 41px;
            text-align: center;
        }
        
        .nav li a {
            display: block;
            width: 100%;
            height: 100%;
            line-height: 40px;
            color: #333;
        }
        
        .nav ul {
            position: absolute;
            /* 隐藏所有的下拉菜单 */
            display: none;
            top: 41px;
            left: 0;
            width: 100%;
            border-left: 1px solid #FECC5B;
            border-right: 1px solid #FECC5B;
        }
        
        .nav>li a:hover {
            background-color: #eee;
        }
        
        .nav ul li {
            border-bottom: 1px solid #FECC5B;
        }
        
        .nav ul li a:hover {
            background-color: #FFF5DA;
        }
    </style>
</head>

<body>
    <div>
        布局方式：<br> 采用ul的布局方式<br>在ul的li标签内放置一个a标签和一个ul标签
        <br> 在子ul标签内放置3个a标签
        <br> 父li标签float：left,子ul标签采取定位的方式定位到父li标签的下面<br> display: none隐藏所有子ul标签，在父li标签上添加鼠标经过(onmouseover)和离开(onmouseout)的事件<br>当 鼠标经过时子ul设置display = 'block'，鼠标离开时子ul设置display = 'none'
    </div>
    <ul class="nav">
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
            </ul>
        </li>
    </ul>

    <script>
        // 获取元素
        var nav = document.querySelector('.nav');
        var lis = nav.children;
        // 添加事件
        for (var i = 0; i < lis.length; i++) {
            lis[i].onmouseover = function() { // 鼠标经过
                // 显示下拉菜单
                this.children[this.children.length - 1].style.display = 'block';
            }
            lis[i].onmouseout = function() { // 鼠标离开
                // 隐藏下拉菜单
                this.children[this.children.length - 1].style.display = 'none';
            }
        }
    </script>
</body>

</html>